//
//  RCActivityDetailDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-28.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCActivityDetailDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "RCMerchantDetailDataModel.h"
#import "NSArray+EX.h"

@implementation RCActivityDetailPicture

@synthesize discountID = _discountID;
@synthesize activityOriginPrice = _activityOriginPrice;
@synthesize activityPresentPrice = _activityPresentPrice;
@synthesize activitySignUp = _activitySignUp;
@synthesize title = _title;
@synthesize content = _content;
@synthesize endTime = _endTime;
@synthesize type = _type;
@synthesize pictureArray = _pictureArray;

-(id)init{
    self = [super init];
    if (self) {
        _discountID = nil;
        _activityOriginPrice = 0.0;
        _activityPresentPrice = 0.0;
        _activitySignUp = 0.0;
        _title = nil;
        _content = nil;
        _endTime = nil;
        _type = ActivityDetalTypePicture;
        _pictureArray = nil;
    }
    return self;
}

-(void)dealloc{
    self.discountID = nil;
    self.title = nil;
    self.content = nil;
    self.endTime = nil;
    self.pictureArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCActivityDetailPicture *retObject = nil;
    retObject = [[RCActivityDetailPicture alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.discountID = [data stringValueForKey:@"discountid" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.activityOriginPrice = [data intValueForKey:@"originalprice" defaultValue:0.0];
    retObject.activityPresentPrice = [data intValueForKey:@"presentprice" defaultValue:0.0];
    retObject.title = [data stringValueForKey:@"title" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.content = [data stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.activitySignUp = [data intValueForKey:@"signup" defaultValue:0];
    retObject.pictureArray = [data arrayValueForKey:@"pic4app" defaultValue:nil];
    retObject.endTime = [data stringValueForKey:@"endtime" defaultValue:nil operation:NSStringOperationTypeTrim];
    return [retObject autorelease];
}

@end


@implementation RCActivityDetailShopInfo

@synthesize shopID = _shopID;
@synthesize shopName = _shopName;
@synthesize type = _type;
@synthesize score = _score;
@synthesize address = _address;
@synthesize telePhone = _telePhone;
@synthesize favourited = _favourited;
@synthesize lat = _lat;
@synthesize lon = _lon;

-(id)init{
    self = [super init];
    if (self) {
        _shopID = nil;
        _shopName = nil;
        _type = ActivityDetalTypeShopInfo;
        _score = 0;
        _address = nil;
        _telePhone = nil;
        _favourited = NO;
        _lat = nil;
        _lon = nil;
    }
    return self;
}

-(void)dealloc{
    self.shopID = nil;
    self.shopName = nil;
    self.address = nil;
    self.telePhone = nil;
    self.lat = nil;
    self.lon = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCActivityDetailShopInfo *retObject = nil;
    retObject = [[RCActivityDetailShopInfo alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.shopID = [data stringValueForKey:@"shopid" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.shopName = [data stringValueForKey:@"shopname" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.score = [data intValueForKey:@"score" defaultValue:0.0];
    retObject.address = [data stringValueForKey:@"address" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.telePhone = [data stringValueForKey:@"tele" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.lat = [data stringValueForKey:@"lat" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.lon = [data stringValueForKey:@"lon" defaultValue:nil operation:NSStringOperationTypeTrim];
    
    NSInteger favourite = [data intValueForKey:@"favorite" defaultValue:0];
    if (favourite == 1) {
        retObject.favourited = YES;
    }else{
        retObject.favourited = NO;
    }
    return [retObject autorelease];
}

@end


@implementation RCActivityDetailContentDetail

@synthesize type = _type;
@synthesize content = _content;
@synthesize pictureArray = _pictureArray;

-(id)init{
    self = [super init];
    if (self) {
        _type = ActivityDetalTypeActivityDetail;
        _content = nil;
        _pictureArray = nil;
    }
    return self;
}

-(void)dealloc{
    self.content = nil;
    self.pictureArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCActivityDetailContentDetail *retObject = nil;
    retObject = [[RCActivityDetailContentDetail alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.content = [data stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.pictureArray = [data arrayValueForKey:@"pics" defaultValue:nil];
    return [retObject autorelease];
}

@end

@implementation RCActivityDetailNotice

@synthesize type = _type;
@synthesize content = _content;

-(id)init{
    self = [super init];
    if (self) {
        _type = ActivityDetalTypeNotice;
        _content = nil;
    }
    return self;
}

-(void)dealloc{
    self.content = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCActivityDetailNotice *retObject = nil;
    retObject = [[RCActivityDetailNotice alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.content = [data stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeTrim];
    return [retObject autorelease];
}

@end

@implementation RCActivityDetailDataModel

@synthesize activityName = _activityName;
@synthesize shopID = _shopID;
@synthesize activityContent = _activityContent;
@synthesize activityPicUrl = _activityPicUrl;
@synthesize lat = _lat;
@synthesize lon = _lon;
@synthesize activityEndTime = _activityEndTime;
@synthesize activityOriginPrice = _activityOriginPrice;
@synthesize activityPresentPrice = _activityPresentPrice;
@synthesize activitySignUp = _activitySignUp;
@synthesize activityDetailItems = _activityDetailItems;

-(id)init{
    self = [super init];
    if (self) {
        _activityName = nil;
        _activityContent = nil;
        _activityPicUrl = nil;
        _activityEndTime = nil;
        _lat = nil;
        _lon = nil;
        _activityEndTime = nil;
        _activityDetailItems = nil;
        _activityOriginPrice = 0;
        _activityPresentPrice = 0;
        _activitySignUp = 0;
        
        _pictureInfo = nil;
        _shopInfo = nil;
        _contentDetail = nil;
        _noticeInfo = nil;
    }
    return self;
}

-(void)dealloc{
    self.activityName = nil;
    self.shopID = nil;
    self.activityContent = nil;
    self.activityPicUrl = nil;
    self.lat = nil;
    self.lon = nil;
    self.activityEndTime = nil;
    self.activityDetailItems = nil;
    
    self.pictureInfo = nil;
    self.shopInfo = nil;
    self.contentDetail = nil;
    self.noticeInfo = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCActivityDetailDataModel *retObject = nil;
    retObject = [[RCActivityDetailDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    
//    retObject.activityName = [dataDic stringValueForKey:@"shopname" defaultValue:nil operation:NSStringOperationTypeTrim];
//    retObject.activityContent = [dataDic stringValueForKey:@"foodname" defaultValue:nil operation:NSStringOperationTypeTrim];
//    retObject.activityPicUrl = [dataDic stringValueForKey:@"picurl" defaultValue:nil operation:NSStringOperationTypeTrim];
//    retObject.lat = [dataDic stringValueForKey:@"lat" defaultValue:nil operation:NSStringOperationTypeTrim];
//    retObject.lon = [dataDic stringValueForKey:@"lon" defaultValue:nil operation:NSStringOperationTypeTrim];
//    retObject.activityEndTime = [dataDic stringValueForKey:@"endtime" defaultValue:nil operation:NSStringOperationTypeTrim];
//    retObject.shopID = [dataDic stringValueForKey:@"shopid" defaultValue:nil operation:NSStringOperationTypeTrim];
//    retObject.activityOriginPrice = [dataDic intValueForKey:@"originalprice" defaultValue:0];
//    retObject.activityPresentPrice = [dataDic intValueForKey:@"presentprice " defaultValue:0];
//    retObject.activitySignUp = [dataDic intValueForKey:@"signup " defaultValue:0];
//    
//    int favourite = [dataDic intValueForKey:@"favorite" defaultValue:0];
//    if (favourite == 1) {
//        retObject.favourited = YES;
//    }else{
//        retObject.favourited = NO;
//    }
//    
//    
//    NSArray *t = [dataDic arrayValueForKey:@"list" defaultValue:nil];
//    NSMutableArray *itemsArray = [[NSMutableArray alloc] init];
//    for (NSDictionary *dic in t) {
//        RCMerchantDetailItem *item = [[RCMerchantDetailItem alloc] initWithDic:dic];
//        [itemsArray addObject:item];
//        [item release];
//    }
//    
//    //添加交通等
//    
//    RCMerchantDetailItem *traffic = [[RCMerchantDetailItem alloc]init];
//    traffic.type = kMerchantDetailType_Traffic;
//    traffic.content = @"交通、营业时间及其他";
//    [itemsArray addObject:traffic];
//    [traffic release];
//    
//    NSInteger otherShop = [dataDic intValueForKey:@"othershop" defaultValue:0];
//    if (otherShop == 1) {
//        RCMerchantDetailItem *otherShop = [[RCMerchantDetailItem alloc]init];
//        otherShop.type = kMerchantDetailType_Othershop;
//        otherShop.content = @"其他分店";
//        [itemsArray addObject:otherShop];
//        [otherShop release];
//    }
//    retObject.activityDetailItems = itemsArray;
//    [itemsArray release];
    
    
    
    NSArray *dictArray = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dictArray || [dictArray count] == 0) {
        return [retObject autorelease];
    }
    for (int i = 0; i < [dictArray count]; i++) {
        NSDictionary *dictItem = [dictArray safeObjectAtIndex:i];
        if (nil == dictItem) {
            continue;
        }
        NSString *type = [dictItem stringValueForKey:@"type" defaultValue:nil operation:NSStringOperationTypeTrim];
        if ([type isEqualToString:@"youhui"]) {
            RCActivityDetailPicture *pictureInfo = [RCActivityDetailPicture parseDataFromJSON:dictItem];
            retObject.pictureInfo = pictureInfo;
        }else if ([type isEqualToString:@"shopinfo"]){
            RCActivityDetailShopInfo *shopInfo = [RCActivityDetailShopInfo parseDataFromJSON:dictItem];
            retObject.shopInfo = shopInfo;
        }else if ([type isEqualToString:@"activedetail"]){
            RCActivityDetailContentDetail *contentDetail = [RCActivityDetailContentDetail parseDataFromJSON:dictItem];
            retObject.contentDetail = contentDetail;
        }else if ([type isEqualToString:@"notice"]){
            RCActivityDetailNotice *notice = [RCActivityDetailNotice parseDataFromJSON:dictItem];
            retObject.noticeInfo = notice;
        }
    }
    
    return [retObject autorelease];
}

@end
